package com.wang.list;

class Solution {
    public String longestPalindrome(String s) {
        if(s.length()<2)return s;
        char[] charArray = s.toCharArray();
        int maxlen = 1;
        int begin = 0;
        for(int i=0;i+1<s.length();i++){
            for(int j=i;j<s.length();j++){
                if(j-i+1>maxlen && isHui(charArray,i,j)){
                    maxlen = j-i+1;
                    begin = i;
                }
            }
        }
        return s.substring(begin,begin+maxlen);
    }
    public boolean isHui(char[] charArray,int i,int j){
        while(i<j){
            if(charArray[i]!=charArray[j]){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.longestPalindrome("ccaba"));
    }
}
